package com.stan.core.spark.ad.commons;

import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.function.VoidFunction;
import scala.Serializable;
import scala.Tuple2;

/**
 * 打印PairDStream<String,String>
 */
public class PairDStreamPrintFunction
        implements VoidFunction<JavaPairRDD<String, String>>, Serializable {
    private String functionName;

    public PairDStreamPrintFunction(String functionName){
        this.functionName = functionName;
    }


    @Override
    public void call(JavaPairRDD<String, String> stringStringJavaPairRDD) throws Exception {
        stringStringJavaPairRDD.foreach(new VoidFunction<Tuple2<String, String>>(){
            @Override
            public void call(Tuple2<String, String> stringStringTuple2) throws Exception {
                System.out.println(functionName + ":" + stringStringTuple2);
            }
        });
    }
}
